home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / elm / elm2.4 / lib / mail_gets.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-11  |  1.8 KB  |  71 lines

  1.  
  2. static char rcsid[] = "@(#)$Id: mail_gets.c,v 5.2 1993/04/12 01:13:30 syd Exp $";
  3.  
  4. /*******************************************************************************
  5.  *  The Elm Mail System  -  $Revision: 5.2 $   $State: Exp $
  6.  *
  7.  *             Copyright (c) 1992 USENET Community Trust
  8.  *******************************************************************************
  9.  * Bug reports, patches, comments, suggestions should be sent to:
  10.  *
  11.  *    Syd Weinstein, Elm Coordinator
  12.  *    elm@DSI.COM            dsinc!elm
  13.  *
  14.  *******************************************************************************
  15.  * $Log: mail_gets.c,v $
  16.  * Revision 5.2  1993/04/12  01:13:30  syd
  17.  * In some cases, with certain editors, the user can create an
  18.  * aliases.text file in which the last line is terminated with an EOF but
  19.  * doesn't have a '\n'.  Currently, elm with complain that the line is
  20.  * too long.
  21.  * From: "William F. Pemberton" <wfp5p@holmes.acc.virginia.edu>
  22.  *
  23.  * Revision 5.1  1992/10/03  22:41:36  syd
  24.  * Initial checkin as of 2.4 Release at PL0
  25.  *
  26.  *
  27.  ******************************************************************************/
  28.  
  29. /** get a line from the mail file, but be tolerant of nulls
  30.  
  31.   The length of the line is returned
  32.  
  33. **/
  34.  
  35. #include <stdio.h>
  36. #include <ctype.h>
  37.  
  38.  
  39. int
  40. mail_gets(buffer, size, mailfile)
  41. char *buffer;
  42. int size;
  43. FILE *mailfile;
  44. {
  45.     register int line_bytes = 0, ch;
  46.     register char *c = buffer;
  47.  
  48.     size--; /* allow room for zero terminator on end, just in case */
  49.     while (!feof(mailfile) && !ferror(mailfile) && line_bytes < size) {
  50.       ch = getc(mailfile); /* Macro, faster than  fgetc() ! */
  51.  
  52.       if (ch == EOF)
  53.       {
  54.         if (line_bytes > 0 && *c != '\n')
  55.         {
  56.             ++line_bytes;
  57.             *c++ = '\n';
  58.         }
  59.         break;
  60.       }
  61.  
  62.       *c++ = ch;
  63.       ++line_bytes;
  64.  
  65.       if (ch == '\n')
  66.         break;
  67.     }
  68.     *c = 0;    /* Actually this should NOT be needed.. */
  69.     return line_bytes;
  70. }
  71.